import Vue from 'vue'
import Router from 'vue-router'
import MainRouter from './router'


Vue.use(Router)
const router = new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [
    ...MainRouter
  ]
});
//路由拦截
router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? to.meta.title : '后台管理系统';
  if (to.meta.auth) {
      next()
  }else{
    if(localStorage.getItem('user_token')){
      if(to.name !== 'login'){
        next()
      }else{
        next({ path: '/' })
      }
    }else{
      next()
    }
  }
})
export default router;